package com.hucc.huccgps;

import java.util.ArrayList;

import com.hucc.huccgps.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

public class CallBroadcastReceiver extends BroadcastReceiver {

	private DBHelper mDBHelper = null;
	
	@Override
	public void onReceive(Context paramContext, Intent paramIntent) {
		String str1 = paramIntent.getAction();
		Log.d("SOS/Service", "----------CallReceiver,onReceive, action=" + str1);
		
		if (mDBHelper == null) {
			mDBHelper = new DBHelper(paramContext);
		}
		
		if ("com.android.intent.fastcall".equals(str1)) {
			ArrayList localArrayList = mDBHelper.getRelativesList();
			int i = Integer.parseInt(paramIntent.getStringExtra("num"));
			
			if ((localArrayList != null) && (i <= localArrayList.size())
					&& (!(((Item)localArrayList.get(i-1)).getNumber().equals("")))) {
				String str2 = ((Item)localArrayList.get(i-1)).getNumber();
				Intent localIntent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + str2));
				localIntent.putExtra("is_sos_call", true);
	            localIntent.addFlags(268435456);
	            paramContext.startActivity(localIntent);
			}else {
				localArrayList.clear();  
                Toast.makeText(paramContext,R.string.str_make_call_fail_hint, 1).show();
			}			
		}
	}
}
